package com.ruoyi.web.controller.market.sys;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.SysConstantInfo;
import com.ruoyi.market.service.ISysConstantInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.SysConstantInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统常量Controller
 * 
 * @author ruoyi
 * @date 2022-08-04
 */
@Controller
@RequestMapping("/merket/constant")
public class SysConstantInfoController extends BaseController
{
    private String prefix = "merket/constant";

    @Autowired
    private ISysConstantInfoService sysConstantInfoService;

    @RequiresPermissions("merket:constant:view")
    @GetMapping()
    public String constant()
    {
        return prefix + "/constant";
    }

    /**
     * 查询系统常量列表
     */
    @RequiresPermissions("merket:constant:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysConstantInfo sysConstantInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = sysConstantInfoService.selectSysConstantInfoListMap(sysConstantInfo);
        mapList = new SysConstantInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出系统常量列表
     */
    @RequiresPermissions("merket:constant:export")
    @Log(title = "系统常量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysConstantInfo sysConstantInfo)
    {
        List<SysConstantInfo> list = sysConstantInfoService.selectSysConstantInfoList(sysConstantInfo);
        ExcelUtil<SysConstantInfo> util = new ExcelUtil<SysConstantInfo>(SysConstantInfo.class);
        return util.exportExcel(list, "系统常量数据");
    }

    /**
     * 新增系统常量
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存系统常量
     */
    @RequiresPermissions("merket:constant:add")
    @Log(title = "系统常量", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysConstantInfo sysConstantInfo)
    {
        return toAjax(sysConstantInfoService.insertSysConstantInfo(sysConstantInfo));
    }

    /**
     * 修改系统常量
     */
    @RequiresPermissions("merket:constant:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysConstantInfo sysConstantInfo = sysConstantInfoService.selectSysConstantInfoById(id);
        mmap.put("sysConstantInfo", sysConstantInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存系统常量
     */
    @RequiresPermissions("merket:constant:edit")
    @Log(title = "系统常量", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysConstantInfo sysConstantInfo)
    {
        return toAjax(sysConstantInfoService.updateSysConstantInfo(sysConstantInfo));
    }

    /**
     * 删除系统常量
     */
    @RequiresPermissions("merket:constant:remove")
    @Log(title = "系统常量", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysConstantInfoService.deleteSysConstantInfoByIds(ids));
    }
}
